<template>
  <div>
    <ElDrawer v-model="visible"
      ><ElForm style="width: 300px">
        <ElFormItem label="请假类型">
          <ElSelect v-model="leaveBillDto.leaveType">
            <ElOption value="sick" label="病假"></ElOption>
            <ElOption value="annual" label="年假"></ElOption>
            <ElOption value="issue" label="事假"></ElOption>
          </ElSelect>
        </ElFormItem>
        <ElFormItem label="开始时间">
          <ElDatePicker type="datetimerange" v-model="leaveBillDto.timeRange"></ElDatePicker>
        </ElFormItem>

        <ElFormItem label="请假原因">
          <ElInput v-model="leaveBillDto.reason"></ElInput>
        </ElFormItem>
        <ElButton @click="insert()">确定</ElButton>
      </ElForm></ElDrawer
    >
  </div>
</template>
<script lang="ts">
/**
 * 页面核心数据结构体说明文档
 *
 *
 */
// import from

export default {
  name: 'MaterialView',
  props: {
    sampleP: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      sampleD: 'value',
      leaveBillDto: {
        leaveType: 'annual',
        // timeStart: '2023-06-03T07:07:10.211Z',
        // timeEnd: '2023-06-06T07:07:10.211Z',
        timeRange: null,
        reason: ''
      },
      visible: false,
      emit: ['postInsert', 'rpagenum']
    }
  },
  computed: {
    /* sampleC() {
      return this.sampleD + "--";
    }, */
  },
  created() {},
  mounted() {},
  methods: {
    // sampleM() {},
    async insert() {
      // 第一步 数据校验
      // 第二部 节流处理
      // 第三部 发送数据
      const d = {
        leaveType: '',
        timeStart: null,
        timeEnd: null,
        reason: ''
      }
      d.leaveType = this.leaveBillDto.leaveType
      d.reason = this.leaveBillDto.reason
      if (this.leaveBillDto.timeRange) {
        d.timeStart = this.leaveBillDto.timeRange[0]
        d.timeEnd = this.leaveBillDto.timeRange[1]
      }
      const res = await axios({
        method: 'post',
        url: 'http://localhost:7001/leave/insert',
        data: d
      })
      ElMessage.success('添加成功')
      console.log(res.data)
      this.visible = false
      this.$emit('postInsert')
      this.$emit('rpagenum')
    },
    show() {
      this.leaveBillDto.reason = ''
      this.visible = true
    }
  },
  watch: {
    // sampleP(n, o) {},
  },
}
</script>

<!--<style scoped>-->
<style lang="scss" scoped></style>
